package com.clothing.entity;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Transient;

import com.clothing.CommonAttributes;
import com.clothing.utils.Utils;

/**
 * @ClassName: Banner 
 * @Description: TODO(banner) 
 * @author Charles 
 * @date 2018年5月7日 上午9:59:12 
 * @version 1.0
 */
@Entity
@Table(name = "banner")
public class Banner extends BaseEntity
{
    /** 
     * @Fields serialVersionUID : TODO(用一句话描述这个变量表示什么) 
     */
    private static final long serialVersionUID = 3975425894012399489L;

    private String image;

    private String url;

    private Boolean enabled;

    @Column(name = "image", nullable = false)
    public String getImage()
    {
        return image;
    }

    public void setImage(String image)
    {
        if (!Utils.isEmpty(image))
        {
            if (image.startsWith(CommonAttributes.SITE_URL))
            {
                image = image.substring(CommonAttributes.SITE_URL.length(),
                        image.length());
            }
        }

        this.image = image;
    }

    @Column(name = "url", nullable = false)
    public String getUrl()
    {
        return url;
    }

    public void setUrl(String url)
    {
        this.url = url;
    }

    @Column(name = "enabled", nullable = false)
    public Boolean getEnabled()
    {
        return enabled;
    }

    public void setEnabled(Boolean enabled)
    {
        this.enabled = enabled;
    }
    
    @Transient
    public String getFullImage()
    {
        if (!Utils.isEmpty(image))
        {
            return CommonAttributes.SITE_URL + image;
        }

        return null;
    }
}
